package com.lw.spring.javademo.jsp;

import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/collection")
public class CollectionJspServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置请求属性
        Map<String, String> dataMap = new HashMap<>(); // 创建一个 Map 集合
        dataMap.put("name", "张三");
        dataMap.put("age", "25");
        dataMap.put("city", "北京");

        // 将 Map 集合放入请求属性
        request.setAttribute("dataMap", dataMap);
        // 跳转到 JSP 页面
        RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/jsp/map.jsp");
        dispatcher.forward(request, response);
    }
}
